package com.performax.database.Dao;

import java.util.*;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.performax.database.Vo.*;
import com.performax.database.oh2game.mapper.EventInfoMapper;

@Service(value = "oh2gameEventDao")
public class Oh2GameEventDao {
	
	@Resource(name = "eventInfoMapper")
	private	EventInfoMapper eventInfoMapper;
	
	public List<EventInfoVo> getEventList(HashMap<String, Object> param){
		return this.eventInfoMapper.getEventList(param);
	}
	
	public int getEventListCnt(HashMap<String, Object> param){
		return this.eventInfoMapper.getEventListCnt(param);
	}
	
	public EventDetailVo getEventDetail(int eventId){
		return this.eventInfoMapper.getEventDetail(eventId);
	}
	
	public PreregVo	getPreregInfo(int eventId, String userId){
		return this.eventInfoMapper.getPreregInfo(eventId, userId);
	}
	
	public List<ReplyInfoVo> getEventReplyList(HashMap<String, Object> param){
		return this.eventInfoMapper.getEventReplyList(param);
	}
	
	public int getEventReplyListCnt(HashMap<String, Object> param){
		return this.eventInfoMapper.getEventReplyListCnt(param);
	}
	
	public List<Integer> getReplyReportType(String userId){
		return this.eventInfoMapper.getReplyReportType(userId);
	}
	
	public int regEventReply(HashMap<String, Object> param, int upperId, int eventId){
		//increase orderNo
		this.eventInfoMapper.incEventReplyOrder(upperId);
		
		//reg event reply info
		this.eventInfoMapper.regEventReply(param);
		
		//increase reply  count at event info
		this.eventInfoMapper.setEventReplyCnt(1, eventId);
		
		//get reply count from event info 
		return this.eventInfoMapper.getEventReplyCnt(eventId);
	}
	
	public int deleteEventReply(int eventId, int replyId){
		//get upperid from current replyinfo
		int	upperId	=	this.eventInfoMapper.getEventReply(replyId);
		
		//if that reply is parent, delete all reply / if not delete one reply
		int deleteCnt	=	this.eventInfoMapper.delEventReply(replyId, upperId);
		
		//decrease reply count at event info
		this.eventInfoMapper.setEventReplyCnt((Math.abs(deleteCnt)*-1), eventId);
		
		//get reply count form event info
		return this.eventInfoMapper.getEventReplyCnt(eventId);
		
	}
	
	
	public List<FriendInfoVo> getFriendList(int eventId){
		return this.eventInfoMapper.getEventFriendList(eventId);
	}
	
	public int regFriend(int eventId, String userId, String regType){
		
		String	snsAccntId	=	this.eventInfoMapper.getSnsAccount(userId);
		int count	=	1;
		
		if(regType.equals("Y")){
			this.eventInfoMapper.regEventFriend(eventId, snsAccntId);
		}else{
			//this.eventInfoMapper.regEventFriend(eventId, snsAccntId);
			this.eventInfoMapper.delEventFriend(eventId, snsAccntId);
			count	=	-1;
		}
		
		this.eventInfoMapper.setEventFriendCnt(count, eventId);
		
		return this.eventInfoMapper.getEventFriendCnt(eventId);
	}
	
	
	public Hashtable<String, Object>	prereg(int eventId, String userId){
		String	couponCode	=	this.eventInfoMapper.getCouponCode(eventId);
		if(couponCode	==	null)	couponCode	=	"";
		
		this.eventInfoMapper.updateCouponUseTp(couponCode, eventId);
		this.eventInfoMapper.prereg(userId, eventId, couponCode);
		this.eventInfoMapper.incPreregCnt(eventId);
	    int		regCnt		=	this.eventInfoMapper.getEventPreregCnt(eventId);
		
	    Hashtable<String, Object> result	=	new	Hashtable<String, Object>();
	    
		result.put("couponCode", couponCode);
		result.put("regCnt", regCnt);
		
	    return result;
	}
	
	
	public int reportEventReply(HashMap<String, Object> param, int replyId){
		this.eventInfoMapper.reportEventReply(param);
		this.eventInfoMapper.incEventReplyReportCnt(replyId);
		return this.eventInfoMapper.getReplyReportCnt(replyId);
	}
	
	
	/*public List<BiInfoVo> getBiList(){
		return this.adinfoMapper.getBiInfo();
	}*/
	
	
	
}
